﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using COFE.Core.Lister;
using COFE.Core;
//using System.Drawing;
//using QuickZip.Converters;
using COFE.Core.Utils;
using System.Drawing;

namespace COFE.IO.ISG
{
    public class IsolatedStoragePropertyProvider : PropertyProviderBase<ISGEntryInfo>
    {
        #region Constructor
        public IsolatedStoragePropertyProvider(string listerKey, ISGEntryInfo entry)
            : base(entry)
        {
            registerProperties(listerKey, entry);
        }
        #endregion

        #region Methods

        private void registerProperties(string listerKey, ISGEntryInfo entry)
        {
            //base.RegisterMethod(FileSystemInfoProperties.FullName, (e,p) => { return e.FullName; });
            base.RegisterMethod(FileSystemInfoProperties.FullParseName, (e, p) =>
            {
                return COFEPath.FormatFullParseName(listerKey, e.RelativePath);
            });

            base.RegisterMethod(FileSystemInfoProperties.ParentParseName, (e, p) =>
            {
                return (String.IsNullOrEmpty(e.RelativePath)) ? null : COFEPath.FormatFullParseName(listerKey, e.GetParent().RelativePath);
            });
            //{ return _rootPath == null ? e.FullName : IOTools.GetRelativePath(e, rootDir); }); 
            //IOTools.GetRelativePath do not support Guid path.
            base.RegisterMethod(FileSystemInfoProperties.Name, (e, p) => { return e.Name; });
            base.RegisterMethod(FileSystemInfoProperties.Label, (e, p) => { return e.Name; });

            base.RegisterMethod(FileSystemInfoProperties.IsExists, (e, p) => { return e.IsExists; });
            base.RegisterMethod(FileSystemInfoProperties.IsFileSystem, (e, p) => { return true; });
            base.RegisterMethod(FileSystemInfoProperties.FileAttributes, (e, p) => { return e.FileAttributes; });

            base.RegisterMethod(FileSystemInfoProperties.COFEAttributes, (e, p) =>
               {
                   return e.IsFolder ? COFEAttributes.FileSystem | COFEAttributes.SubEntriesCanChange | COFEAttributes.Browsable :
                     COFEAttributes.FileSystem;
               });

            if (!entry.IsFolder)
            {

            }
            else
            {
                base.RegisterMethod(DirectoryInfoProperties.DirectoryType,
                    (e, p) => { return String.IsNullOrEmpty(entry.RelativePath) ? DirectoryTypeEnum.dtVolume : DirectoryTypeEnum.dtFolder; });
                base.RegisterMethod(DirectoryInfoProperties.IsFileBasedFS, (e, p) => { return false; });
            }

            //base.RegisterMethod(FileSystemInfoProperties.CreationTimeUtc,
            //    (e,p) => { return e.CreationTimeUtc; });
            //base.RegisterMethod(FileSystemInfoProperties.LastAccessTimeUtc,
            //    (e,p) => { return e.LastAccessTimeUtc; });
            //base.RegisterMethod(FileSystemInfoProperties.LastWriteTimeUtc,
            //    (e,p) => { return e.LastWriteTimeUtc; });

            //if (!entries.IsFolder)
            //{
            //    base.RegisterMethod(IconProperties.Icon,
            //        (e,p) =>
            //        {
            //            return Icon.ExtractAssociatedIcon(e.Name).ToBitmap().EnsureBitmapSize(IconProperties.Icon);
            //        });
            //}


        }

        #endregion

        #region Data


        #endregion

        #region Public Properties


        #endregion

    }
}
